﻿Imports System
Imports System.IO
Imports System.Text


Public Class FinishingProcess

    Public Func As Functions = New Functions
    Dim FeatureChainKey As Integer
    Dim FeatureType As Integer

    '加工情報の宣言------------------------------------------------------------------------------------------------------
    Public Property OperationName As String = "N/A"
    Public Property MachiningType As Integer = 0
    '1:フェースミル加工 2:輪郭加工 3:ポケット加工 4:ドリル加工 5:スパイラル加工 6:その他（割り当てられていない加工）
    Public Property ToolID As String = "N/A"
    Public Property SpindleSpeed As Long = 0
    Public Property XYFeedrate As Double = 0
    Public Property ZFeedrate As Double = 0
    Public Property MachiningMode As Integer = 0
    'FaceMill:
    '   1: 一方向  2:双方向
    'PockettMill:
    '   0:一方向   1:Zig-Zag   2:同心-In   3:同心-Out
    'CountourMill:
    '   1:DepthFirst    2:Widthfirst
    'SpiralMill:
    '   0:内から外  1:外から内
    Public Property StepOver As Double = 2
    Public Property TotalDepth As Double = 0
    Public Property IncrementalDepth As Double = 0
    Public Property StartingDepth As Double = 0
    Public Property MachiningStrategy As Integer = 0
    '0:ダウンカット   1:アップカット
    Public Property PassesNum As Integer = 0
    Public Property StockAllowanceWall As Double
    Public Property StockAllowanceFloor As Double

    '中仕上げ代の宣言------------------------------------------------------------------------------------------------------
    Dim FinishingWidthWall As Double
    Dim FinishingWidthFloor As Double

    '製品形状の宣言------------------------------------------------------------------------------------------------------
    Dim ShapeXMax, ShapeXMin, ShapeYMax, ShapeYMin, ShapeZMax, ShapeZmin As Double
    Dim Depth As Double
    Dim Point(10, 2) As Double


    '検索対象のモデルの情報の宣言-----------------------------------------------------------------------------------------
    Dim ModelCode(100) As Integer
    Dim FeatureCode(100) As Integer

    '参照先モデルのCode---------------------------------------------------------------------------------------------------
    Dim RefModelCode As Integer
    Dim RefFeatureCode As Integer

    '起動前に読み込む関数（素材形状を読み込み，認識）
    Public Sub PreLoarForm(ByVal Key As Integer, ByRef SemiFinishingStockWall As Double, ByVal SemiFinishingStockFloor As Double)
        Dim path As String
        Dim Read As StreamReader
        Dim Reader As String
        Dim FeatureNum, FeatureCounter As Integer
        Dim PointNum, PointCounter As Integer
        Dim retval(5) As String
        Dim flag As Boolean = False

        '中仕上げ代の設定
        FinishingWidthWall = SemiFinishingStockWall
        FinishingWidthFloor = SemiFinishingStockFloor

        '製品形状を読み込み（対象のFeatureChainKeyのみ）
        flag = False
        path = "ShapeDataEsp.txt"
        Read = New StreamReader(path)

        Reader = Read.ReadLine
        retval = Reader.Split(CChar(" "))
        FeatureNum = CInt(retval(0))

        For FeatureCounter = 0 To FeatureNum - 1
            If flag Then Exit For

            Reader = Read.ReadLine
            retval = Reader.Split(CChar(" "))
            FeatureType = CInt(retval(1))

            Reader = Read.ReadLine
            retval = Reader.Split(CChar(" "))
            FeatureChainKey = CInt(retval(0))
            PointNum = CInt(retval(2))

            For PointCounter = 0 To PointNum - 1

                Reader = Read.ReadLine
                retval = Reader.Split(CChar(" "))

                '対象のFeatureChain であれば，座標の情報の取得
                If FeatureChainKey = Key Then
                    flag = True
                    Point(PointCounter, 0) = CDbl(retval(0))
                    Point(PointCounter, 1) = CDbl(retval(1))
                    Point(PointCounter, 2) = CDbl(retval(2))
                End If
            Next
            Reader = Read.ReadLine
            retval = Reader.Split(CChar(" "))
            If FeatureChainKey = Key Then
                Depth = CDbl(retval(0))
            End If
        Next

    End Sub

    '起動時に読み込む関数（データベース内の類似度を読み込んで表示）
    Private Sub DataReusingForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim Code As Integer = Func.Key2Code(FeatureChainKey)
        Dim path As String = "Search.txt"
        Dim Reader As StreamReader = New StreamReader(path)
        Dim Read As String
        Dim retval(10) As String
        Dim FeatureNum As Integer
        Dim MatchNum As Integer
        Dim CodeDB As Integer


        ComboBoxInfo.Items.Clear()

        '各種類似度の宣言
        Dim TotalSimilarity(100) As Double      '総合類似度
        Dim ReferencedRate(100) As Double       '被引用度
        Dim MaterialSimilarity(100) As Double   '素材類似度
        Dim Roughness(100) As Double         '表面粗さ


        '類似度の読み込み（Search.txtより読み込み）--------------------------------------------------------------------------------
        '*形状類似度/寸法類似度は不要だが、マッチングの結果の取得にSearch.txtの読み込みが必要
        Read = Reader.ReadLine
        retval = Read.Split(CChar(" "))

        FeatureNum = CInt(retval(0))

        For FeatureCoutner As Integer = 0 To FeatureNum - 1
            Read = Reader.ReadLine
            retval = Read.Split(CChar(" "))
            CodeDB = CInt(retval(0))
            MatchNum = CInt(retval(1))

            For MatchCount As Integer = 0 To MatchNum - 1
                Read = Reader.ReadLine
                retval = Read.Split(CChar(" "))
                If CodeDB = Code Then
                    ModelCode(MatchCount) = CInt(retval(0))
                    FeatureCode(MatchCount) = CInt(retval(1))
                End If
            Next
            If CodeDB = Code Then Exit For '??
        Next

        '--------------------------------------------------------------------------------------------------------------------------


        '被引用率の読み込み（ReferencedDatabase.txtから読み込み）------------------------------------------------------------------
        '        path = "Ref Database.txt"
        '        Dim Reader2 As IO.StreamReader = New IO.StreamReader(path)
        '        Dim ModelCode4R As Integer
        '        Dim FeatureCode4R As Integer
        '        Dim RefNum As Integer
        '        Dim TotalNum As Integer
        '        While Not Reader2.Peek = -1
        '            Read = Reader2.ReadLine
        '            retval = Read.Split(CChar(" "))
        '            ModelCode4R = CInt(retval(0))
        '            FeatureCode4R = CInt(retval(1))
        '            RefNum = CInt(retval(2))
        '            TotalNum = CInt(retval(3))
        '            For i As Integer = 0 To MatchNum
        '                If ModelCode4R = ModelCode(i) And FeatureCode4R = FeatureCode(i) Then
        '                    ReferencedRate(i) = RefNum / TotalNum
        '                End If
        '            Next
        '        End While

        'MEMO 131002 被引用率を無視（=１に設定）
        For i As Integer = 0 To MatchNum
            ReferencedRate(i) = 1.0
        Next

        '---------------------------------------------------------------------------------------------------------------------------



        '素材情報の読み込み/ 素材類似度の計算---------------------------------------------------------------------------------------
        path = "Material.txt"
        Dim Reader3 As IO.StreamReader = New IO.StreamReader(path)
        Dim MaterialValue As Double
        Dim ModelCode4M As Integer
        Dim FeatureCode4M As Integer
        Dim MaterialValueDB As Double

        'Queryの素材情報の読み込み
        Read = Reader3.ReadLine()
        MaterialValue = CDbl(Read)

        path = "Material Database.txt"
        Dim Reader4 As IO.StreamReader = New StreamReader(path)

        'DB内の素材情報読み込み
        While Not Reader4.Peek = -1
            Read = Reader4.ReadLine
            retval = Read.Split(CChar(" "))
            ModelCode4M = CInt(retval(0))
            FeatureCode4M = CInt(retval(1))
            MaterialValueDB = CDbl(retval(2))
            For i As Integer = 0 To MatchNum
                If ModelCode4M = ModelCode(i) And FeatureCode4M = FeatureCode(i) Then
                    MaterialSimilarity(i) = 1 - Math.Abs(MaterialValueDB - MaterialValue) / Math.Max(MaterialValue, MaterialValueDB)
                    Exit For
                End If
            Next

        End While

        '-----------------------------------------------------------------------------------------------------------------------



        '表面粗さの読み込み----------------------------------------------------------------------------------------------------
        path = "Roughness.txt"
        Dim Reader5 As IO.StreamReader = New IO.StreamReader(path)
        Dim RoughnessValue As Double
        Dim ModelCode4R As Integer
        Dim FeatureCode4R As Integer
        Dim RoughnessValueDB As Double
        Dim Counter As Integer = 0

        'Queryの素材情報の読み込み
        Read = Reader5.ReadLine()
        RoughnessValue = CDbl(Read)

        path = "Roughness Database.txt"
        Dim Reader6 As IO.StreamReader = New StreamReader(path)

        'DB内の素材情報読み込み
        While Not Reader6.Peek = -1
            Counter += 1
            Read = Reader6.ReadLine
            retval = Read.Split(CChar(" "))
            ModelCode4R = CInt(retval(0))
            FeatureCode4R = CInt(retval(1))
            RoughnessValueDB = CDbl(retval(2))
            For i As Integer = 0 To MatchNum
                If ModelCode4R = ModelCode(i) And FeatureCode4R = FeatureCode(i) Then
                    Roughness(i) = RoughnessValueDB
                    Exit For
                End If
            Next
        End While

        '-----------------------------------------------------------------------------------------------------------------------

        'TotalSimilarityの計算--------------------------------------------------------------------------------------------------
        For i As Integer = 0 To MatchNum
            TotalSimilarity(i) = ReferencedRate(i) * MaterialSimilarity(i)
        Next

        '-----------------------------------------------------------------------------------------------------------------------

        'TotalSimilarityでバブルソート
        For i As Integer = 0 To MatchNum - 1
            For j As Integer = MatchNum - 1 To i + 1 Step -1
                If (TotalSimilarity(j) > TotalSimilarity(j - 1)) Then
                    Dim tModelCode As Integer = ModelCode(j)
                    ModelCode(j) = ModelCode(j - 1)
                    ModelCode(j - 1) = tModelCode

                    Dim tFeatureCode As Integer = FeatureCode(j)
                    FeatureCode(j) = FeatureCode(j - 1)
                    FeatureCode(j - 1) = tFeatureCode

                    Dim tMaterialSimilarity As Double = MaterialSimilarity(j)
                    MaterialSimilarity(j) = MaterialSimilarity(j - 1)
                    MaterialSimilarity(j - 1) = tMaterialSimilarity

                    Dim tReferencedRate As Double = ReferencedRate(j)
                    ReferencedRate(j) = ReferencedRate(j - 1)
                    ReferencedRate(j - 1) = tReferencedRate

                    Dim tTotalSimilarity As Double = TotalSimilarity(j)
                    TotalSimilarity(j) = TotalSimilarity(j - 1)
                    TotalSimilarity(j - 1) = tTotalSimilarity
                End If
            Next
        Next


        'RoughnessGapでバブルソート
        For i As Integer = 0 To MatchNum - 1
            For j As Integer = MatchNum - 1 To i + 1 Step -1
                If (RoughnessValue - Roughness(j) < RoughnessValue - Roughness(j - 1)) Then
                    Dim tRoughness As Double = Roughness(j)
                    Roughness(j) = Roughness(j - 1)
                    Roughness(j - 1) = tRoughness

                    Dim tModelCode As Integer = ModelCode(j)
                    ModelCode(j) = ModelCode(j - 1)
                    ModelCode(j - 1) = tModelCode

                    Dim tFeatureCode As Integer = FeatureCode(j)
                    FeatureCode(j) = FeatureCode(j - 1)
                    FeatureCode(j - 1) = tFeatureCode

                    Dim tMaterialSimilarity As Double = MaterialSimilarity(j)
                    MaterialSimilarity(j) = MaterialSimilarity(j - 1)
                    MaterialSimilarity(j - 1) = tMaterialSimilarity

                    Dim tReferencedRate As Double = ReferencedRate(j)
                    ReferencedRate(j) = ReferencedRate(j - 1)
                    ReferencedRate(j - 1) = tReferencedRate

                    Dim tTotalSimilarity As Double = TotalSimilarity(j)
                    TotalSimilarity(j) = TotalSimilarity(j - 1)
                    TotalSimilarity(j - 1) = tTotalSimilarity
                End If
            Next
        Next

        'ソートの結果に従って表示()
        For MatchCount As Integer = 0 To MatchNum - 1
            If RoughnessValue - Roughness(MatchCount) >= 0 Then
                ComboBoxInfo.Items.Add("Similarity:" + TotalSimilarity(MatchCount).ToString("0.000") + " Model:" + CStr(ModelCode(MatchCount)) + "-" + CStr(FeatureCode(MatchCount)) + "Roughness:" + CStr(Roughness(MatchCount)) + " Sim.M.:" + MaterialSimilarity(MatchCount).ToString("0.000"))
            End If
        Next

    End Sub

    '計算ボタンを押した時の挙動（各種深さ/パス数の計算）
    Private Sub ButtonCalDepth_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonCalDepth.Click
        StockAllowanceWall = CDbl(TextBoxStockAllowanceWall.Text)
        StepOver = CDbl(TextBoxStepOver.Text)

        '輪郭加工であれば，パス数を計算（値を変更していれば，boxの背景色を変更）
        If MachiningType = 2 Then
            PassesNum = CInt(Math.Ceiling((FinishingWidthWall - StockAllowanceWall) / StepOver))
            If Not TextBoxPassesNum.Text = CStr(PassesNum) Then
                TextBoxPassesNum.BackColor = Color.Red
                TextBoxPassesNum.ForeColor = Color.White
                TextBoxPassesNum.Text = CStr(PassesNum)
            End If
        End If
        Dim IsUpside As Boolean

        '各種深さを計算
        IsUpside = Func.IsUpSideOrNot(FeatureType)
        If IsUpside Then
            StartingDepth = FinishingWidthFloor + Depth
            StartingDepth = -StartingDepth
            TotalDepth = 0
        Else
            StartingDepth = FinishingWidthFloor - ShapeZMax
            StartingDepth = -StartingDepth
            TotalDepth = Depth
        End If

        'スタート深さのboxを変更（値を変更していれば，背景色を変更）
        If Not TextBoxStartingDepth.Text = CStr(StartingDepth) Then
            TextBoxStartingDepth.BackColor = Color.Red
            TextBoxStartingDepth.ForeColor = Color.White
            TextBoxStartingDepth.Text = CStr(StartingDepth)
        End If

        '合計深さのboxを変更（値を変更していれば，背景色を変更）
        If Not TextBoxTotalDepth.Text = CStr(TotalDepth) Then
            TextBoxTotalDepth.BackColor = Color.Red
            TextBoxTotalDepth.ForeColor = Color.White
            TextBoxTotalDepth.Text = CStr(TotalDepth)
        End If

    End Sub

    '適応ボタンを押した時の挙動（加工データを読み込み）
    Private Sub ButtonApply_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonApply.Click
        '加工データの読み込み/表示

        '読み込み用のReader
        Dim path As String = "FiniShingProcess Database.txt"
        Dim Reader As StreamReader = New StreamReader(path)
        Dim Read As String
        Dim retval(10) As String
        Dim ModelCodeInDB As Integer
        Dim FeatureCodeInDB As Integer

        '参照先モデルのCodeを取得
        RefModelCode = ModelCode(CInt(ComboBoxInfo.SelectedIndex))
        RefFeatureCode = FeatureCode(CInt(ComboBoxInfo.SelectedIndex))

        '表示する対象のモデルの情報まで読み込み
        Do
            Read = Reader.ReadLine()
            retval = Read.Split(CChar(" "))
            ModelCodeInDB = CInt(retval(0))
            FeatureCodeInDB = CInt(retval(1))

            '表示する対象のモデルの情報でなければ，取得して破棄
            If Not ModelCodeInDB = RefModelCode Or Not FeatureCodeInDB = RefFeatureCode Then
                For i As Integer = 0 To 15
                    Read = Reader.ReadLine()
                Next
            End If
        Loop Until ModelCodeInDB = RefModelCode And FeatureCodeInDB = RefFeatureCode

        '表示する対象のモデルの情報を読み込み，表示
        'オペレーション名
        Read = Reader.ReadLine()
        OperationName = Read
        TextBoxOperationName.Text = OperationName

        '加工の種類
        Read = Reader.ReadLine()
        retval = Read.Split(CChar(" "))
        MachiningType = CInt(retval(0))
        ComboBoxMachiningType.SelectedIndex = MachiningType

        '工具ID
        Read = Reader.ReadLine()
        retval = Read.Split(CChar(" "))
        ToolID = Read
        TextBoxToolID.Text = ToolID

        '回転数
        Read = Reader.ReadLine()
        retval = Read.Split(CChar(" "))
        SpindleSpeed = CLng(retval(0))
        TextBoxSpindleSpeed.Text = CStr(SpindleSpeed)

        'XY送り速度
        Read = Reader.ReadLine()
        retval = Read.Split(CChar(" "))
        XYFeedrate = CDbl(retval(0))
        TextBoxXYFeedrate.Text = CStr(XYFeedrate)

        'Z送り速度
        Read = Reader.ReadLine()
        retval = Read.Split(CChar(" "))
        ZFeedrate = CDbl(retval(0))
        TextBoxZFeedrate.Text = CStr(ZFeedrate)

        '加工モード
        Read = Reader.ReadLine()
        retval = Read.Split(CChar(" "))
        MachiningMode = CInt(retval(0))
        ComboBoxMachiningMode.Items.Clear()
        With ComboBoxMachiningMode
            Select Case MachiningType
                Case 1  'フェースミル加工
                    .Items.Add("")
                    .Items.Add("一方向")
                    .Items.Add("双方向")
                    TextBoxPassesNum.Enabled = False
                    Label17.Enabled = False
                Case 2  '輪郭加工
                    .Items.Add("")
                    .Items.Add("深さ方向から")
                    .Items.Add("幅方向から")
                    TextBoxPassesNum.Enabled = True
                    Label17.Enabled = True
                Case 3  'ポケット加工
                    .Items.Add("一方向")
                    .Items.Add("ジグザグ")
                    .Items.Add("同心円-In")
                    .Items.Add("同心円-Out")
                    TextBoxPassesNum.Enabled = False
                    Label17.Enabled = False
                Case 5  'スパイラル加工
                    .Items.Add("内から外")
                    .Items.Add("外から内")
                    TextBoxStepOver.Enabled = False
                    Label7.Enabled = False
                    TextBoxPassesNum.Enabled = False
                    Label17.Enabled = False
            End Select
            .SelectedIndex = MachiningMode
        End With

        'ステップオーバー
        Read = Reader.ReadLine()
        retval = Read.Split(CChar(" "))
        StepOver = CDbl(retval(0))
        TextBoxStepOver.Text = CStr(StepOver)

        '増分深さ
        Read = Reader.ReadLine()
        retval = Read.Split(CChar(" "))
        IncrementalDepth = CDbl(retval(0))
        TextBoxIncrementalDepth.Text = CStr(IncrementalDepth)

        '深さ合計
        Read = Reader.ReadLine()
        retval = Read.Split(CChar(" "))
        TotalDepth = CDbl(retval(0))
        TextBoxTotalDepth.Text = CStr(TotalDepth)

        'スタート深さ
        Read = Reader.ReadLine()
        retval = Read.Split(CChar(" "))
        StartingDepth = CDbl(retval(0))
        TextBoxStartingDepth.Text = CStr(StartingDepth)

        '加工方法
        Read = Reader.ReadLine()
        retval = Read.Split(CChar(" "))
        MachiningStrategy = CInt(retval(0))
        ComboBoxMachiningStrategy.SelectedIndex = MachiningStrategy

        'パス数
        Read = Reader.ReadLine()
        retval = Read.Split(CChar(" "))
        PassesNum = CInt(retval(0))
        If MachiningType = 2 Then
            TextBoxPassesNum.Enabled = True
            Label17.Enabled = True
            TextBoxPassesNum.Text = CStr(PassesNum)
        Else
            Label17.Enabled = False
            TextBoxPassesNum.Enabled = False
        End If

        '壁許容残り代
        Read = Reader.ReadLine()
        retval = Read.Split(CChar(" "))
        StockAllowanceWall = CDbl(retval(0))
        TextBoxStockAllowanceWall.Text = CStr(StockAllowanceWall)

        '床許容残り代
        Read = Reader.ReadLine()
        retval = Read.Split(CChar(" "))
        StockAllowanceFloor = CDbl(retval(0))
        TextBoxStockAllowanceFloor.Text = CStr(StockAllowanceFloor)


    End Sub

    'MachiningTypeを見て MachiningModeのリストを設定/ PassesNumの変更を許可
    Private Sub ComboBoxMachiningType_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBoxMachiningType.SelectedIndexChanged
        ComboBoxMachiningMode.Items.Clear()
        With ComboBoxMachiningMode
            Select Case ComboBoxMachiningType.SelectedIndex
                Case 1
                    .Items.Add("")
                    .Items.Add("一方向")
                    .Items.Add("双方向")
                    TextBoxPassesNum.Enabled = False
                    Label17.Enabled = False
                Case 2
                    .Items.Add("")
                    .Items.Add("深さ方向から")
                    .Items.Add("幅方向から")
                    TextBoxPassesNum.Enabled = True
                    Label17.Enabled = True
                Case 3
                    .Items.Add("一方向")
                    .Items.Add("ジグザグ")
                    .Items.Add("同心円-In")
                    .Items.Add("同心円-Out")
                    TextBoxPassesNum.Enabled = False
                    Label17.Enabled = False
                Case 5
                    .Items.Add("内から外")
                    .Items.Add("外から内")
                    TextBoxStepOver.Enabled = False
                    Label7.Enabled = False
                    TextBoxPassesNum.Enabled = False
                    Label17.Enabled = False
            End Select
        End With
    End Sub

    'OKボタンの挙動（フォーム内の値を取得/記録）
    Private Sub ButtonOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonOK.Click
        Dim path As String = "FinishingProcessData.txt"
        Dim Write As IO.StreamWriter = New IO.StreamWriter(path)

        'フォーム内の値の取得
        MachiningType = ComboBoxMachiningType.SelectedIndex
        OperationName = TextBoxOperationName.Text
        ToolID = TextBoxToolID.Text
        SpindleSpeed = CLng(TextBoxSpindleSpeed.Text)
        XYFeedrate = CDbl(TextBoxXYFeedrate.Text)
        ZFeedrate = CDbl(TextBoxZFeedrate.Text)
        MachiningMode = ComboBoxMachiningMode.SelectedIndex
        StepOver = CDbl(TextBoxStepOver.Text)
        TotalDepth = CDbl(TextBoxTotalDepth.Text)
        IncrementalDepth = CDbl(TextBoxIncrementalDepth.Text)
        StartingDepth = CDbl(TextBoxStartingDepth.Text)
        MachiningStrategy = ComboBoxMachiningStrategy.SelectedIndex
        PassesNum = CInt(TextBoxPassesNum.Text)
        StockAllowanceWall = CDbl(TextBoxStockAllowanceWall.Text)
        StockAllowanceFloor = CDbl(TextBoxStockAllowanceFloor.Text)

        'フォーム内の値の記録
        Write.Write(CStr(Func.Key2Code(FeatureChainKey)) + vbCrLf)
        Write.Write(OperationName + vbCrLf)
        Write.Write(CStr(MachiningType) + vbCrLf)
        Write.Write(ToolID + vbCrLf)
        Write.Write(CStr(SpindleSpeed) + vbCrLf)
        Write.Write(CStr(XYFeedrate) + vbCrLf)
        Write.Write(CStr(ZFeedrate) + vbCrLf)
        Write.Write(CStr(MachiningMode) + vbCrLf)
        Write.Write(CStr(StepOver) + vbCrLf)
        Write.Write(CStr(TotalDepth) + vbCrLf)
        Write.Write(CStr(IncrementalDepth) + vbCrLf)
        Write.Write(CStr(StartingDepth) + vbCrLf)
        Write.Write(CStr(MachiningStrategy) + vbCrLf)
        Write.Write(CStr(PassesNum) + vbCrLf)
        Write.Write(CStr(StockAllowanceWall) + vbCrLf)
        Write.Write(CStr(StockAllowanceFloor) + vbCrLf)
        Write.Close()


        'RefDatabaseの更新
        '        path = "Ref Database.txt"
        '        Dim Read As IO.StreamReader = New IO.StreamReader(path)
        '        Dim Reader As String
        '        Dim retval(10) As String
        '        Dim DataNum As Integer = 0
        '        Dim ModelCode(100) As Integer
        '        Dim FeatureCode(100) As Integer
        '        Dim RefNum(100) As Integer
        '        Dim TotalNum(100) As Integer

        '現在までのデータを取得，値の更新
        '        While Not Read.Peek = -1
        '            Reader = Read.ReadLine
        '            retval = Reader.Split(CChar(" "))
        '            ModelCode(DataNum) = CInt(retval(0))
        '            FeatureCode(DataNum) = CInt(retval(1))
        '            RefNum(DataNum) = CInt(retval(2))
        '            TotalNum(DataNum) = CInt(retval(3))
        '            If ModelCode(DataNum) = RefModelCode And FeatureCode(DataNum) = RefFeatureCode Then
        '                RefNum(DataNum) += 1
        '            End If
        '            TotalNum(DataNum) += 1
        '            DataNum += 1
        '        End While
        '        Read.Close()

        'データの更新を書き込み
        ' Dim Write2 As IO.StreamWriter = New IO.StreamWriter(path)
        ' For i As Integer = 0 To DataNum - 1
        '     Write2.Write(CStr(ModelCode(i)) + " " + CStr(FeatureCode(i)) + " " + CStr(RefNum(i)) + " " + CStr(TotalNum(i)) + vbCrLf)
        ' Next
        ' Write2.Close()



        Me.Close()
    End Sub

    'Cancelボタンの挙動（値を取得せず終了）
    Private Sub ButtonCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonCancel.Click
        Me.Close()
    End Sub


End Class